﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace FinWeb3.Models.Helpers
{
    public static class StringExtensions
    {
        public static string Capitalize(this string original)
        {
            return original.Substring(0, 1).ToUpper() + original.Substring(1);
        }

        public static DateTime ToDateTime(this string date)
        {
            if (date.Length != 8)
                throw new ArgumentException("A data deve estar no formato ddmmyyyy!", "date");

            return new DateTime(
                int.Parse(date.Substring(4)),
                int.Parse(date.Substring(2, 2)),
                int.Parse(date.Substring(0, 2)));
        }

        public static string FormatDataText(this string date)
        {
            var dateTime = DateTime.Parse(date);

            return dateTime.ToString("ddMMyyyy");
        }
    }
}
